home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////
- //
- // ADOBE SYSTEMS INCORPORATED
- // Copyright 2002 Adobe Systems Incorporated
- // All Rights Reserved
- //
- // NOTICE: Adobe permits you to use, modify, and
- // distribute this file in accordance with the terms
- // of the Adobe license agreement accompanying it.
- // If you have received this file from a source
- // other than Adobe, then your use, modification,
- // or distribution of it requires the prior
- // written permission of Adobe.
- //
- //////////////////////////////////////////////////
-
- //////////////////////////////////////////////////
- //
- // Complex Animation.js
- //
- // DESCRIPTION
- //
- // This script uses a mathematical formula to apply
- // motion to an object and creates more key frames.
- // It also shows how to apply similar principals to
- // other stopwatches.
- //
- // HOW TO USE
- //
- // Create any object and select it in the Composition.
- // Select Automation > Run Automation Script > Complex Animation.js
- // Click on Preview Mode to view the object animation.
- //
- //////////////////////////////////////////////////
-
- // Main Code [Execution of script begins here]
-
- // Check if any composition is open
- if(application.compositions.length > 0){
- comp = application.currentComposition;
- if(comp.selection.length >= 1){ // Checks if at least one object is selected
- var objs = comp.selection; // Store all selected objects in the array objs
- for(var i=0 ; i < objs.length ; i++){
- // Assign the objects in objs, one by one to target and apply complex animation to them
- target = objs[i];
- application.currentComposition.saveSelection(); // saves the current selection
- complexAnimation(target, 50, 50, 36); // Function complexAnimation called
- application.currentComposition.restoreSelection(); // restores the saved selection
- }
- }
- else{ // If no objects are selected brings the Console window up
- Console.show();
- // Writes to the Console
- Console.write("Please select the objects to apply the Animation and run the script again.\n");
- }
- }
- else{// if no composition open
- // opens a new composition
- comp = application.newComposition();
- Console.show();
- Console.write("New Composition opened\nPlease create and select the objects to apply the Animation and run the script again.\n");
- }
-
-
- // Add your own functions here
-
- //////////////////////////////////////////////////
- //
- // complexAnimation:
- //
- // Animates the currently selected object using a
- // mathematical formula
- //
- // target: The object to animate.
- // x: The change in x position.
- // y: The change in y position.
- // frames: Total number of frames throughout which the animation will last.
- //
- //////////////////////////////////////////////////
-
- function complexAnimation(target, x, y, frames)
- {
- var x_original; // variable for the original x position
- var y_original; // variable for the original y position
- var frame0; // the initial / current frame to start the animation from
- var keyFrameRate = 3; // this script will create a key frame every 3 frames
-
- frame0 = target.startFrame; // take the current frame value and store it
- x_original = target.position.x; // store initial x position
- y_original = target.position.y; // store initial y position
-
- target.stopwatch.position = true; // turn on the stopwatch for position
- target.stopwatch.rotation = true; // turn on the stopwatch for rotation
-
- // Note: The initial positions are not stored by turning on the stopwatch.
- // The stopwatch only records changes AFTER it's been turned on.
-
- // loop to animate the object across the frames
- for (var i=0 ; i < frames ; i += keyFrameRate) {
- target.currentFrame = frame0 + i; // First frame
- target.position.x = x_original + x * Math.sin((i/frames) * (2 * Math.PI));
- target.position.y = y_original + y * Math.cos((i/frames) * (2 * Math.PI));
- target.rotation = (i / frames) * 720;
- }
- return;
- }
-
-